Hands-On Network Programming with C by Lewis Van Winkle

Hands-On Network Programming with C by Lewis Van Winkle

Author:Lewis Van Winkle
Language: eng
Format: mobi
Publisher: Praful Palekar
Published: 2019-05-10T12:20:35+00:00


FILE *fp = fopen(full_path, "rb");

if (!fp) {

send_404(client);

return;

}

If fopen() succeeds, then we can use fseek() and ftell() to determine the requested file's size. This is important, as we need to use the file's size in the Content-Length header. The following code finds the file size and stores it in the cl variable:

/*web_server.c except*/

fseek(fp, 0L, SEEK_END);

size_t cl = ftell(fp);

rewind(fp);

Once the file size is known, we also want to get the file's type. This is used in the Content-Type header. We already defined a function, get_content_type(), which makes this task easy. The content type is store in the variable ct by the following code:

/*web_server.c except*/



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.